﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cxx.BLL;
using Cxx.Common;
using Cxx.Entity;

namespace Cxx.OrderManagerSys
{
    public partial class CalculateTotal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btBrowse_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtCustomerName.Text))
            {
                JScript.Alert(Page,"请输入收货单位");
                return;
            }
            if (!Order.ExistCustomer(txtCustomerName.Text))
            {
                JScript.Alert(Page, "该客户从未下单");
                return;
            }
            string condition = MyWebHelper.SelectKey(pnlSearch, out _);
            var total = Order.CalculateTotal(condition);
            lbTotal.Text = "该时间段内总计金额：" + total;
            lbTotal.Visible = true;
            string time = $"【{txtStartTime.Text}】-【{txtEndTime.Text}】";
            CusTotalLogsInfo cusTotalLogsInfo = new CusTotalLogsInfo
            {
                Amount = total,
                OperateTime = DateTime.Now,
                Receiver = txtCustomerName.Text,
                SelectTime = time
            };
            CusTotalLogs.Insert(cusTotalLogsInfo);
        }
    }
}